<template>
  <div>
    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
      <div class="widget am-cf">
        <div class="widget-head am-cf">
          <div class="widget-title am-fl">教师任教情况(学科指标)</div>
        </div>

        <div class="widget-body  am-fr">
          <div class="am-u-sm-8 am-u-md-8 am-u-lg-2">
            <div class="am-form-group">
              <el-select
                v-model="query.areaTeamId"
                placeholder="请选择地区"
              >
                <el-option
                  v-for="(item, index) in areaTeams"
                  :key="index"
                  :label="item.text"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </div>
          </div>

          <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
            <div class="am-form-group">
              <el-select
                v-model="query.periodId"
                placeholder="选择期数"
              >
                <el-option
                  v-for="(item, index) in periods"
                  :key="index"
                  :label="item.periodName"
                  :value="item.periodId"
                >
                </el-option>
              </el-select>
            </div>
          </div>
          <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
            <div class="am-form-group">
              <el-select
                placeholder="科目"
                v-model="query.subjectId"
                clearable
              >
                <el-option
                  v-for="(item, index) in subjects"
                  :key="index"
                  :value="item.value"
                  :label="item.text"
                ></el-option>
              </el-select>
            </div>
          </div>

          <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
            <div class="am-form-group">
              <el-input
                v-model="query.teacherName"
                placeholder="任课老师"
              >
              </el-input>
            </div>
          </div>

          <div class="am-u-sm-20 am-u-md-20 am-u-lg-8 am-u-end">
            <div class="am-form-group">
              <button
                @click="handleSearch"
                type="button"
                class="am-btn am-btn-default am-btn-success"
              ><span class="am-icon-search"></span>查询
              </button>
              <button
                @click="exportFile"
                type="button"
                class="am-btn am-btn-default am-btn-success"
              >导出
              </button>
            </div>
          </div>
          <div class="am-u-sm-12">
            <el-table
              :data="tableData"
              border
              empty-text="暂无数据"
              stripe
              style="min-width: 100%"
            >

              <el-table-column
                min-width="100"
                prop="areaTeamName"
                label="区域"
              >
              </el-table-column>
              <el-table-column
                min-width="140"
                label="期数"
                prop="periodName"
              >
              </el-table-column>
              <el-table-column
                min-width="100"
                label="科目"
                prop="subjectName"
              >
              </el-table-column>

              <el-table-column
                min-width="150"
                prop="teacherName"
                label="任课老师"
              >
              </el-table-column>
              <el-table-column
                min-width="150"
                prop="level"
                label="星级"
              >
              </el-table-column>
              <el-table-column
                min-width="150"
                prop="classNum"
                label="班量"
              >
              </el-table-column>
              <el-table-column
                min-width="150"
                prop="lectureNum"
                label="任教总讲次"
              >
              </el-table-column>
              <el-table-column
                min-width="150"
                prop="totalClassAdvance"
                label="产生营收"
              >
              <template scope="scope">
                 <div>{{(scope.row.totalClassAdvance/scope.row.totalClassLectureAmount*scope.row.lectureNum).toFixed(2)}}</div>
              </template>
              </el-table-column>
            </el-table>
          </div>
        </div>
        <div class="am-u-lg-12 am-cf">
          <div class="am-fr">
            <pagination
              v-bind:total="total"
              v-bind:pageNo="pageNo"
              v-bind:pageSize="pageSize"
              isShowPageSize
              @pageSizeChange="sizeChange"
              @paging="loadTableData"
            />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import io from '../../lib/io'
import Pagination from '../base/Pagination.vue'
import moment from 'moment'
import upload from '../base/upload'
import Clipboard from 'clipboard'
import conf from '../../lib/conf'
export default {
  data: function() {
    return {
      total: 0,
      pageSize: 10,
      pageNo: 1,
      tableData: [{}],
      viewSchoolList: [],
      showSchoolList: [],
      totalSession: [],
      schoolInputData: [],
      isShowSchoolInputData: [],
      currentActId: '',
      periods: [],
      dateTime: [],
      studentRefundIds: '',
      studentRefundIdsArr: [],
      query: {
        areaTeamId: '',
        subjectId: '',
        periodId: '',
        teacherName: ''
      }
    }
  },
  components: {
    Pagination
  },
  watch: {
    'query.areaTeamId': function(newValue, oldValue) {
      if (oldValue) {
        this.query.busTeamId = ''
        this.query.periodId = ''
      }
      if (!oldValue && this.query.periodId) {
        this.loadTableData()
      }
      this.loadPeriodData()
    },
    'query.periodId': function(newValue, oldValue) {
      if (!oldValue && this.query.areaTeamId) {
        this.loadTableData()
      }
    }
  },
  computed: {
    areaTeams() {
      let options = (this.$root.config.areaTeams || []).map(item => {
        if (!this.query.areaTeamId) {
          this.query.areaTeamId = item.areaTeamId
        }
        return { value: item.areaTeamId, text: item.name }
      })
      return options
    },
    subjects: function() {
      return this.$root.config.subjects.map(function(item) {
        return { value: item.subjectId, text: item.subjectName }
      })
    }
  },
  mounted() {},
  methods: {
    handleSelectionChange(selection) {
      this.studentRefundIdsArr = selection
    },
    loadPeriodData() {
      io.post(
        io.apiAdminPeriodListForAreaTeam,
        {
          areaTeamId: this.query.areaTeamId
        },
        ret => {
          if (ret.success) {
            this.periods = ret.data
            this.query.periodId = this.periods[0].periodId
          } else {
            this.$alert(ret.desc)
          }
        }
      )
    },
    handleSearch() {
      this.loadTableData(1)
    },
    sizeChange(val) {
      this.pageSize = val
    },
    exportFile() {
      if (!this.query.periodId) {
        this.$alert('请选择期数')
        return
      }
      io.downloadFile(
        io.exportTeacherTeachDetailPage,
        this.formatData(this.query),
        ret => {
          if (ret.success) {
          } else {
            this.$alert(ret.desc)
          }
        }
      )
    },
    loadTableData(pageNo) {
      this.pageNo = pageNo || this.pageNo || 1
      if (!this.query.periodId) {
        this.$alert('请选择期数')
        return
      }
      this.$showLoading()
      io.post(
        io.findTeacherTeachDetailPage,
        Object.assign({}, this.formatData(this.query), {
          pageNo: this.pageNo,
          pageSize: this.pageSize
        }),
        ret => {
          this.$hiddenLoading()
          if (ret.success) {
            this.tableData = ret.data.list
            this.total = ret.data.total
          } else {
            this.$alert(ret.desc)
          }
        }
      )
    },
    formatData(data) {
      return {
        areaTeamId: data.areaTeamId,
        subjectId: data.subjectId,
        periodId: data.periodId,
        teacherName: data.teacherName
      }
    }
  }
}
</script>
<style lang="less" scoped>
</style>
